﻿using System.Collections.Generic;
using System.Linq;
using tomenglertde.SetupProject.Model;

namespace tomenglertde.SetupProject.ViewModel
{
    public class SetupProjectOutput : SetupItem
    {
        public SetupProjectOutput(NodeEntity node, SetupProjectViewModel project) 
            : base(node, project)
        {
        }

        public string OutputGroup
        {
            get
            {
                return Node.GetValue("OutputGroupCanonicalName");
            }
            set
            {
                Node.SetValue("OutputGroupCanonicalName", value);
            }
        }

        public string ProjectGuid
        {
            get
            {
                return Node.GetValue("OutputProjectGuid");
            }
            set
            {
                Node.SetValue("OutputProjectGuid", value);
            }
        }

        public string SourcePath
        {
            get
            {
                return Node.GetValue("SourcePath");
            }
            set
            {
                Node.SetValue("SourcePath", value);
            }
        }

        public override string Id
        {
            get
            {
                return Node.Name.Split(':')[1];
            }
            set
            {
                Node.Name = Node.Name.Split(':')[0] + ":" + value;
            }
        }

        public IEnumerable<object> Children
        {
            get
            {
                return ChildIds.Select(id => (object)Project.Files.FirstOrDefault(file => file.Id == id) ?? id);
            }
        }

        public SetupProjectOutput Clone()
        {
            return new SetupProjectOutput(Node.Clone(Node.Parent), Project);
        }
    }
}
